package com.example.zhangxin.myhuatuob2b.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.example.zhangxin.myhuatuob2b.R;
import com.example.zhangxin.myhuatuob2b.fragment.home.store.MobileRegisterFragment;
import com.example.zhangxin.myhuatuob2b.fragment.home.store.UserNameRegisterFragment;

import java.util.ArrayList;

public class RegisteredActivity extends FragmentActivity {

    private TabLayout reg_tablayout;
    private ViewPager reg_viewpager;
    private ArrayList<String> data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_registered);
        data = new ArrayList<>();
        data.add("用户注册");
        data.add("手机注册");
        initView();
        reg_viewpager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                Fragment fragment = null;
                switch (position){
                    case 0:
                        fragment = new UserNameRegisterFragment();
                        break;
                    case 1:
                        fragment = new MobileRegisterFragment();
                        break;
                }
                return fragment;
            }

            @Override
            public int getCount() {
                return data.size();
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return data.get(position);
            }
        });

        reg_tablayout.setupWithViewPager(reg_viewpager);
    }

    private void initView() {
        reg_tablayout = (TabLayout) findViewById(R.id.reg_tablayout);
        reg_viewpager = (ViewPager) findViewById(R.id.reg_viewpager);
    }
}
